package com.csun.cmny.provider.service.impl;

import com.csun.cmny.base.enums.ErrorCodeEnum;
import com.csun.cmny.provider.exceptions.CacBizException;
import com.csun.cmny.provider.model.dto.OmcOldManDto;
import com.csun.cmny.provider.model.dto.user.UserRoleDto;
import com.csun.cmny.provider.model.service.UacUserFeignApi;
import com.csun.cmny.provider.model.vo.CacOldManVo;
import com.csun.cmny.provider.model.vo.RpcUserVo;
import com.csun.cmny.provider.service.OmcOldmanFeignApi;
import com.csun.cmny.provider.service.UacRpcService;
import com.csun.cmny.util.wrapper.Wrapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Auther: chisj chisj@foxmal.com
 * @Date: 2019-05-27 09:55
 * @Description: the class uac rpc service impl
 */
@Slf4j
@Service
public class UacRpcServiceImpl implements UacRpcService {

    @Resource
    private UacUserFeignApi uacUserFeignApi;

    @Resource
    private OmcOldmanFeignApi omcOldmanFeignApi;


    /**
     * 根据角色和组织Id查询用户列表
     *
     * @param userRoleDto user role dto
     * @return
     */
    @Override
    public List<RpcUserVo> queryUserListByRoleCodeAndGroupId(UserRoleDto userRoleDto) {

        try {
            Wrapper<List<RpcUserVo>> wrapper = uacUserFeignApi.queryUserListByRoleCodeAndGroupId(userRoleDto);
            if (null == wrapper) {
                throw new CacBizException(ErrorCodeEnum.GL99990002);
            }
            if (wrapper.error()) {
                throw new CacBizException(ErrorCodeEnum.UAC10018002);
            }

            List<RpcUserVo> result = wrapper.getResult();

            assert result != null;

            return result;
        } catch (Exception e) {
            log.error("queryUserListByRoleCodeAndGroupId={}", e.getMessage(), e);
        }

        return null;
    }

    /**
     * 根据姓名模糊查询老人信息--现在评估模块使用
     *
     * @param omcOldManDto
     * @return
     */
    @Override
    public List<CacOldManVo> showCacOldMan(OmcOldManDto omcOldManDto) {
     try {
            Wrapper<List<CacOldManVo>> wrapper = omcOldmanFeignApi.showCacOldMan(omcOldManDto);
            if (null == wrapper) {
                throw new CacBizException(ErrorCodeEnum.GL99990002);
            }
            if (wrapper.error()) {
                throw new CacBizException(ErrorCodeEnum.UAC10018002);
            }

            List<CacOldManVo> result = wrapper.getResult();

            assert result != null;

            return result;
        } catch (Exception e) {
            log.error("showCacOldMan={}", e.getMessage(), e);
        }

        return null;
    }
}
